package TemplateMethod;
import java.io.FileInputStream;
import java.io.IOException;//异常
//文件读取的模板方法
public abstract class AbstractReader {
    public final void readFile(String filePath){
        FileInputStream fis=null;//声明出入流对象并初始化
        try{
        fis=openFile(filePath);//打开文件
        readContent(fis);//读取文件
        }catch (IOException e){
            System.out.println("文件操作异常"+e.getMessage());
        }finally {
            closeFile(fis);//关闭文件
        }
    }
    //抽象方法
    protected abstract FileInputStream openFile(String failPath) throws IOException;
    protected abstract void readContent(FileInputStream fis) throws IOException;
    protected abstract void closeFile(FileInputStream fis);
}
